/*
 * @Author: 郑刘利
 * @Date: 2020-03-17 15:48:18
 * @LastEditors: 郑刘利
 * @LastEditTime: 2020-03-17 16:14:02
 * @Description: file content
 */

/**
 * 公共interactor，里面封装了authService服务
 */
class CommonInteractor {
    private static _instance?: CommonInteractor;
    public static get instance() {
        return this._instance ? this._instance : new CommonInteractor({});
    }

    private _authService: any;
    private constructor(authService: any) {
        this._authService = authService;
    }

    public getAuthToken() {
        return fakeAuth.isAuthenticated;
    }
    public authenticate(cb: VoidFunction) {
        fakeAuth.authenticate(cb);
    }
    public singOut(cb: VoidFunction) {
        fakeAuth.signOut(cb);
    }
}

const fakeAuth = {
    isAuthenticated: false,
    authenticate(cb: VoidFunction) {
        fakeAuth.isAuthenticated = true;
        setTimeout(cb, 100); // fake async
    },
    signOut(cb: VoidFunction) {
        fakeAuth.isAuthenticated = false;
        setTimeout(cb, 100);
    }
};

export default CommonInteractor.instance;
